/**
 * File    : LabelValueComboBoxFieldBinding.java
 * Created : 2009-3-30
 * By      : LuHuiguo
 */
package com.luhuiguo.cms.client.widget.binding;

import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.luhuiguo.cms.client.widget.LabelValueComboBox;

/**
 * 显示标签、值对应的下拉框绑定。
 * 
 * @author LuHuiguo
 * @version $Id: LabelValueComboBoxFieldBinding.java 163 2010-05-10 15:36:28Z luhuiguo@gmail.com $
 */
public class LabelValueComboBoxFieldBinding<T> extends FieldBinding {

    /**
     * 绑定的下拉框。
     */
    protected LabelValueComboBox<T> labelValueComboBox;

    /**
     * 构造函数。
     * 
     * @param field
     *            绑定的输入框
     * @param property
     *            绑定的属性
     */
    public LabelValueComboBoxFieldBinding(LabelValueComboBox<T> field, String property) {
        super(field, property);
        this.labelValueComboBox = field;
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.extjs.gxt.ui.client.binding.FieldBinding#onConvertFieldValue(java.lang.Object)
     */
    @Override
    protected Object onConvertFieldValue(Object value) {
        return labelValueComboBox.getOptionValue();
    }

    /**
     * {@inheritDoc}
     * 
     * @see com.extjs.gxt.ui.client.binding.FieldBinding#onConvertModelValue(java.lang.Object)
     */
    @SuppressWarnings("unchecked")
    @Override
    protected Object onConvertModelValue(Object value) {
        return labelValueComboBox.findModel((T) value);
    }
    

}
